/*
 * Display.java
 * iRoomMonitor1.0
 * 11/06/10
 */

package RoomNanny.SpotSensors;

import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;

/**
 * This class initializes and controls the LED display on a SunSpot.
 *
 * @author Erin Griffiths
 */
public class Display {

    private ITriColorLED[] leds = EDemoBoard.getInstance().getLEDs();

    /**
     * Denotes a sensor that is talking to the basestation, but not connected
     * in order to send data. The LED is red.
     */
    public void sensorUnconnected(){
        //turns on red
        leds[7].setRGB(255, 0, 0);
        leds[7].setOn();
    }
    /**
     * Denotes that a sensor is currently busy with some task. The LED is red.
     */
    public void busy(){
        //turns on red
        leds[6].setRGB(255, 0, 0);
        leds[6].setOn();
    }
    /**
     * Displays a number in binary on the LED. Ones are white. Zeros are off.
     *
     * @param id
     */
    public void binaryID(int id){
        //converts to binary
        char[] binaryID = Integer.toBinaryString(id).toCharArray();
        for (int i = 0; i < binaryID.length; i++) {
            if (binaryID[i] == '1') {
                leds[(leds.length - binaryID.length) + i].setRGB(100, 100, 100);
                leds[(leds.length - binaryID.length) + i].setOn();
            }
        }
    }
    /**
     * Denotes that the light is on. LED is green.
     */
    public void lightOn(){
        // Set green
        leds[6].setRGB(0, 255, 0);
        leds[6].setOn();
    }
    /**
     * Denotes that the light is off. LED is blue.
     */
    public void lightOff(){
        // Set blue
        leds[6].setRGB(0, 0, 255);
        leds[6].setOn();
    }
    /**
     * Denotes that the sensor is sending data. LED is white.
     */
    public void sendingData(){
        //turns on white
        leds[7].setRGB(255, 255, 255);
        leds[7].setOn();
    }
    /**
     * Turns off all the LEDs on the display.
     */
    public void reset(){
        for (int i = 0; i < leds.length; i++) {
            leds[i].setOff();
        }
    }
    /**
     * Denotes the power level of the sensor. All LEDs a green means sensor
     * is fully charged.
     *
     * @param x number of LEDs to light
     */
    public void powerLed(int x){
        for (int i=0; i < x; i++){
            leds[i].setRGB(0, 225, 0);
            leds[i].setOn();

        }

    }

}
